﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;



using TimKen.DataEntity;
namespace TimKen.Web.Admin.UserAccount
{
    public partial class User_List : TimKen.App.AdminPage
    {
        TimKen.BussLogic.UserAccountManager ua = new TimKen.BussLogic.UserAccountManager();
        TimKen.BussLogic.CustomerManager cm = new TimKen.BussLogic.CustomerManager();

        public override string ActionCode
        {
            get
            {
                return "85";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsInRoleAdmin()) 
            //{
            //    AuthorityFailed();
            //}
            if (!this.IsPostBack)
            {
                BindDpl();
                BindGrid();
                BindResources();
            }
        }

        private void BindGrid()
        {
            DataSet ds = ua.GetUserAccountPageList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, dplRole.SelectedValue,
                this.txtCustomerID.Text == "" ? "-1" : this.txtCustomerID.Text, txtUserName.Text.Trim(), this.LanguageID);
            //   dplCustomerID.SelectedValue
            grdUserList.DataSource = ds;
            grdUserList.DataBind();
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[1].Rows[0]["total"]);
        }
        private void BindDpl()
        {
            //dplCustomerID.DataSource = cm.GetEnableCustomerNameAndID("");

            //if (LanguageID == (int)LanguageEnum.Chinese)
            //    dplCustomerID.DataTextField = "CustomerName";
            //else
            //    dplCustomerID.DataTextField = "CustomerForeignName";


            //dplCustomerID.DataValueField = "CustomerID";
            //dplCustomerID.DataBind();
            //dplCustomerID.Items.Insert(0, new ListItem(GetLangString("PleaseSelect"), "-1"));

            dplRole.DataSource = ua.GetRoles(this.LanguageID);
            dplRole.DataTextField = "RoleName";
            dplRole.DataValueField = "RoleID";
            dplRole.DataBind();

            dplRole.Items.Insert(0, new ListItem(GetLangString("PleaseSelect"), "-1"));
        }
        protected void btFilter_Click(object sender, EventArgs e)
        {
            int num = 0;
            int.TryParse(this.txtCustomerID.Text, out num);
            if (num != 0)
            {
                BindGrid();
            }
        }

        protected void btNoFilter_Click(object sender, EventArgs e)
        {
            // dplCustomerID.SelectedValue = "-1";
            dplRole.SelectedValue = "-1";

            txtUserName.Text = "";
            BindGrid();
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            BindGrid();
        }

        protected void grdUserList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "DeleteEvent")
            {

                ua.Delete(e.CommandArgument.ToString(), this.CurrentUserName);
                BindGrid();
            }
        }

        public void BindResources()
        {
            btFilter.Text = GetLangString("Search");
            btNoFilter.Text = GetLangString("ClearSearchCondition");
        }
    }
}
